<template>
    <div class="photoinfo-container">
        <!-- 头部 -->
        <div class="photoinfo-top">
            <h4>{{ photoinfo.title}}</h4>
            <div class="time-bar">
                <span>发表时间：{{photoinfo.add_time}}次</span><span>点击：{{photoinfo.click}}次</span>
            </div>
        </div>
        <hr>

        <!-- 缩略图区 -->
            <div class="photo-list">
               <img class="preview-img" v-for="(item, index) in list" :src="item.src" height="100" @click="$preview.open(index, list)" :key="item.src">   
            </div>
        <!-- 简介 -->
        <div class="photoinfo-content">
            <p v-html="photoinfo.content"></p>
            </div>
        
        <!-- 评论子组件 -->
        <commentbox :id="id"></commentbox>
        
    </div>
</template>

<script>
import commentbox from'../comments/comment.vue'
export default {
    data(){
        return {
            id: this.$route.params.id,
            photoinfo:[],
            list: []
        }
    },
    created(){
        this.getphotoinfo();
        this.getphoto()
    },
    methods:{
        getphotoinfo(){
            this.$http.get("api/getimageInfo/"+this.id).then((result)=>{
                this.photoinfo = result.body.message[0];
            })
        },
        getphoto(){
            //vue-previews事件：每个图片对象必须有w和h
            this.$http.get("api/getthumimages/" + this.id).then((result)=>{
                if(result.body.status === 0){
                    //循环每个图片对象，给图像对象添加w和H
                    result.body.message.forEach(item => {
                        item.w=600;
                        item.h=400;
                    });
                    // 保存对象数组
                    this.list = result.body.message
                }
            })
        }
    },
    components:{
        commentbox
    }
}
</script>

<style lang="less" scoped>
    .photoinfo-container{
        padding: 0 5px;
        .photoinfo-top{
        h4{
            color: lightblue;
            text-align: center;
            font-size: 16px;
            margin: 10px 0;
        }
        .time-bar{
            display: flex;
            justify-content: space-between;
            span{
                color: lightgrey;
                font-size: 13px;
            }
        }
        }
        .photoinfo-content{
            p{
                color: black;
                line-height: 30px;
                font-weight: bold;
            }
        }
        .photo-list{
            display: flex;
            flex-wrap: wrap;
            img{
                margin: 10px
            }
        }
    }
    
</style>
